<template>
  <up-popup :show="state.paramsPopupShow" mode="bottom" bgColor="transparent">
    <view class="params-popup" bgColor="transparent">
      <view class="title">
        <view>筛选设置</view>
        <up-icon
          name="close"
          color="#1A1A1A"
          size="20"
          @click="state.paramsPopupShow = false"
        ></up-icon>
      </view>
      <view class="tab-item">
        <view class="label">任务类型</view>
        <view class="tab-group">
          <view
            :class="`tab ${state.params.is_machine.has(2) && 'active'}`"
            @click="chnageParams(2, state.params.is_machine)"
          >
            首次
          </view>
          <view
            :class="`tab ${state.params.is_machine.has(1) && 'active'}`"
            @click="chnageParams(1, state.params.is_machine)"
          >
            机算
          </view>
          <view
            :class="`tab ${state.params.is_machine.has(0) && 'active'}`"
            @click="chnageParams(0, state.params.is_machine)"
          >
            手算
          </view>
        </view>
      </view>
      <view class="tab-item">
        <view class="label">任务状态</view>
        <view class="tab-group">
          <view
            :class="`tab ${state.params.status.has(5) && 'active'}`"
            @click="chnageParams(5, state.params.status)"
          >
            已完成
          </view>
          <view
            :class="`tab ${state.params.status.has(0) && 'active'}`"
            @click="chnageParams(0, state.params.status)"
          >
            校验中
          </view>
          <view
            :class="`tab ${state.params.status.has(2) && 'active'}`"
            @click="chnageParams(2, state.params.status)"
          >
            排队中
          </view>
          <view
            :class="`tab ${state.params.status.has(6) && 'active'}`"
            @click="chnageParams(6, state.params.status)"
          >
            计算失败
          </view>
        </view>
      </view>
      <view class="btn-group">
        <view class="btn" @click="resetParams()">重置</view>
        <view
          class="btn"
          @click="
            initData();
            state.paramsPopupShow = false;
          "
          >确定
        </view>
      </view>
    </view>
  </up-popup>
</template>

<script setup lang="ts">
import { onUnload } from "@dcloudio/uni-app";
import state, { initData } from "../useState";

onUnload(() => {
  resetParams();
});
const resetParams = () => {
  state.params.is_machine.clear();
  state.params.status.clear();
  initData();
};
const chnageParams = (status: number, list: Set<number>) => {
  list.has(status) ? list.delete(status) : list.add(status);
};
</script>

<style scoped lang="scss">
.params-popup {
  padding: 16px;
  border-radius: 20px 20px 0px 0;
  background-color: #fff;

  .title {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 15px;
    font-weight: 500;
    line-height: 23px;
    color: rgba(0, 0, 0, 0.9);
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 74px;
    box-sizing: border-box;
    padding: 8px 0;
    .label {
      font-size: 12px;
      line-height: 100%;
      color: rgba(0, 0, 0, 0.6);
    }
    .tab-group {
      display: flex;
      gap: 12px;
      .tab {
        flex: 1;
        height: 30px;
        line-height: 30px;
        text-align: center;
        border-radius: 4px;
        background: rgba(0, 0, 0, 0.05);
        font-size: 12px;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.9);
      }
      .tab.active {
        background: rgba(42, 101, 255, 0.1);
        color: #2a65ff;
      }
    }
  }

  .btn-group {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    .btn {
      flex: 1;
      height: 38px;
      line-height: 38px;
      text-align: center;
      border-radius: 4px;
      font-size: 14px;
      font-weight: 500;
    }
    .btn:nth-child(1) {
      background: rgba(0, 0, 0, 0.05);
      color: rgba(0, 0, 0, 0.9);
    }
    .btn:nth-child(2) {
      background: #2a65ff;
      color: rgba(255, 255, 255, 0.95);
    }
  }
}
</style>
